package com.menggudf.common;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.sms.SmsClient;
import com.baidubce.services.sms.SmsClientConfiguration;
import com.baidubce.services.sms.model.SendMessageRequest;
import com.baidubce.services.sms.model.SendMessageResponse;

public class SMS {

    private static final String ACCESS_KEY_ID     = "00b06d9b97e545b1a05c4a6bf892e89d";
    private static final String SECRET_ACCESS_KEY = "88ef5adfe051448692a4e7a1a6233a3d";

    private static SmsClient    client            = null;

    private static final Logger LOGGER            = LoggerFactory.getLogger(SMS.class);

    private SMS() {

    }

    static {
        // 初始化一个SmsClient
        SmsClientConfiguration config = new SmsClientConfiguration();
        config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY));
        client = new SmsClient(config);
    }

    public static SendMessageResponse getSMSSend(
            String templateId,
            List<String> receiver,
            String contentVar) {
        try {
            SendMessageRequest request = new SendMessageRequest();// 构建SendMessageRequest对象

            request.setTemplateId(templateId);// 设置短信模板ID
            request.setContentVar(contentVar);// 设置短信模板内容变量的替换值
            request.setReceiver(receiver);// 设置接收人列表
            SendMessageResponse sendResponse = new SendMessageResponse();
            
            LOGGER.info("msg send:"+request);
            sendResponse = client.sendMessage(request);// 请求Server

            return sendResponse;
        } catch (RuntimeException e) {
            LOGGER.error("SendMessage Failed", e);
            throw e;
        }
    }
}
